select sum(x.impo_cheque) as total_cheques
from
(
select ctem.idval, max(ctem.impo) as impo_cheque
from comm
join ambempsuc on comm.codambsuc = ambempsuc.codambsuc
join ctem on comm.id = ctem.idcomm
where comm.idpad = :IdPad and
ctem.tipovalt in ('CHE-T', 'CHE-E', 'ECH-T') and
:SYS_Emp = ambempsuc.codambemp
group by 1
) x
join val on x.idval = val.id
left join pad on val.idpadquelotiene = pad.id
where (val.fechacobro > cast(now() as date)) or (pad.codpadr like 'F.CAJ%')